#include "lumiere.h"


/******************************/
/* Constructeur / Destructeur */
/******************************/


Lumiere::Lumiere() : Objet()
{
  setSpecular(1.0,1.0,1.0,1.0);
  setAmbient(0.0,0.0,0.0,1.0);
  setDiffuse(1.0,1.0,1.0,1.0);
  setAttenuation(0.0,0.0,1.0);
  setDirection(0.0,0.0,-1.0);
  _cutoff=180.0;
  _exponent=0.0;
}

Lumiere::~Lumiere()
{
}





/***************************************/
/******** Getters / Setters ************/
/***************************************/

void Lumiere::setSpecular(const float r, const float g, const float b, const float a)
{
  _specular[0]=r;
  _specular[1]=g;
  _specular[2]=b;
  _specular[3]=a;
}

void Lumiere::getSpecular(float &r, float &g, float &b, float &a)
{
  r=_specular[0];
  g=_specular[1];
  b=_specular[2];
  a=_specular[3];
}

void Lumiere::setAmbient(const float r, const float g, const float b, const float a)
{
  _ambient[0]=r;
  _ambient[1]=g;
  _ambient[2]=b;
  _ambient[3]=a;
}

void Lumiere::getAmbient(float &r, float &g, float &b, float &a)
{
  r=_ambient[0];
  g=_ambient[1];
  b=_ambient[2];
  a=_ambient[3];
}

void Lumiere::setDiffuse(const float r, const float g, const float b, const float a)
{
  _diffuse[0]=r;
  _diffuse[1]=g;
  _diffuse[2]=b;
  _diffuse[3]=a;
}

void Lumiere::getDiffuse(float &r, float &g, float &b, float &a)
{
  r=_diffuse[0];
  g=_diffuse[1];
  b=_diffuse[2];
  a=_diffuse[3];
}

void Lumiere::setCutoff(float angle)
{
  _cutoff=angle;
}

float Lumiere::getCutoff()
{
  return _cutoff;
}

void Lumiere::setExponent(const float expo)
{
  _exponent=expo;
}

float Lumiere::getExponent()
{
  return _exponent;
}

void Lumiere::setDirection(const float x, const float y, const float z)
{
  _direction[0]=x;
  _direction[1]=y;
  _direction[2]=z;
}

void Lumiere::getDirection(float &x, float &y, float &z)
{
  x=_direction[0];
  y=_direction[1];
  z=_direction[2];
}

void Lumiere::setAttenuation(const float quad, const float linear, const float constant)
{
  _attenuation[0]=quad;
  _attenuation[1]=linear;
  _attenuation[2]=constant;
}

void Lumiere::getAttenuation(float &quad, float &linear, float &constant)
{
  quad=_attenuation[0];
  linear=_attenuation[1];
  constant=_attenuation[2];
}

void Lumiere::setID(int id)
{
  _lightID=id;
}

int Lumiere::getID()
{
  return _lightID;
}



/*********************************/
/******* Fonction de dessin ******/
/*********************************/


void Lumiere::display()
{

glEnable(_lightID);
/*glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
*/
  glLightf(_lightID, GL_SPOT_EXPONENT, _exponent);
  glLightf(_lightID, GL_SPOT_CUTOFF, _cutoff);
  glLightf(_lightID, GL_QUADRATIC_ATTENUATION, _attenuation[0]);
  glLightf(_lightID, GL_LINEAR_ATTENUATION, _attenuation[1]);
  glLightf(_lightID, GL_CONSTANT_ATTENUATION, _attenuation[2]);
  glLightfv(_lightID, GL_AMBIENT, _ambient);
  glLightfv(_lightID, GL_DIFFUSE, _diffuse);
  glLightfv(_lightID, GL_SPECULAR, _specular);
  glLightfv(_lightID, GL_POSITION, _position);
  glLightfv(_lightID, GL_SPOT_DIRECTION, _direction);
/*
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
*/
/*
glPushMatrix();
glTranslatef(_position[0], _position[1],_position[2]);
//glDisable(GL_LIGHTING);
glColor4f(0.0,0.0,1.0,0.5);
glutSolidSphere(1.5,10,10);
//glEnable(GL_LIGHTING);

glPopMatrix();
*/
}


